﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuanLyThuoc
{
    class DieuKhien
    {
        public void chayChucNang()
        {
            int lenh = -1;
            while (lenh != 0)
            {
                DanhSachNhomThuoc dsNhomThuoc = new DanhSachNhomThuoc();
                dsNhomThuoc.docFile();
                DanhSachThuoc dsThuoc = new DanhSachThuoc();
                dsThuoc.docFile();
                DanhSachNhanVien dsNV = new DanhSachNhanVien();
                dsNV.docFile();
                DanhSachKhachHang dsKH = new DanhSachKhachHang();
                dsKH.docFile();
                DanhSachHoaDon dsHD = new DanhSachHoaDon();
                dsHD.docFile();
                DanhSachChiTietHD dsCTHD = new DanhSachChiTietHD();
                dsCTHD.docFile();

                Console.Write("\n>>>>>>>>>>>>DANH MUC QUAN LY<<<<<<<<<<<<");
                Console.Write("\n========================================");
                Console.Write("\nChon danh muc:");
                Console.Write("\n\t1. Quan ly nhom thuoc");
                Console.Write("\n\t2. Quan ly thuoc");
                Console.Write("\n\t3. Quan ly nhan vien");
                Console.Write("\n\t4. Quan ly khach hang");
                Console.Write("\n\t5. Quan ly hoa don");
                Console.Write("\n\t6. Chi tiet hoa don");
                Console.Write("\n\t0. Thoat");
                Console.Write("\n========================================\n");
                while (int.TryParse(Console.ReadLine(), out lenh) == false)
                {
                    Console.Write("\nNhap sai! vui long nhap lai");
                }
                switch (lenh)
                { 
                    case 1:
                        
                        int chonNhom = -1;
                        while (chonNhom != 0)
                        {
                            Console.Write("\n_____QUAN LY NHOM THUOC____");
                            Console.Write("\n----------------------------");
                            Console.Write("\nChon chuc nang:");
                            Console.Write("\n\t1. Nhap nhom thuoc");
                            Console.Write("\n\t2. Tim nhom thuoc");
                            Console.Write("\n\t3. Sua nhom thuoc");
                            Console.Write("\n\t4. Xoa nhom thuoc");
                            Console.Write("\n\t5. Xuat toan bo nhom thuoc");
                            //Console.Write("\n\t6. Doc danh sach nhom thuoc tu tep");
                            Console.Write("\n\t0. Tro lai danh muc");
                            Console.Write("\n----------------------------\n");
                            while (int.TryParse(Console.ReadLine(), out chonNhom) == false)
                            {
                                Console.Write("\nNhap sai, vui long nhap lai!");
                            }
                            switch (chonNhom)
                            { 
                                case 1:
                                    Console.Write("\n***************************************\n");
                                    dsNhomThuoc.NhapDS();
                                    Console.Write("\nDa nhap xong");
                                    Console.Write("\n***************************************\n");
                                    break;
                                case 2:
                                    Console.Write("\n***************************************\n");
                                    dsNhomThuoc.timKiem();
                                    Console.Write("\n***************************************\n");
                                    break;
                                case 3:
                                    Console.Write("\n***************************************\n");

                                    Console.Write("\nNhap ma nhom can sua: ");
                                    string maSua = Console.ReadLine();
                                    Console.Write("\nNhap ten nhom can sua: ");
                                    string tenSua = Console.ReadLine();
                                    if (dsNhomThuoc.SuaNT(maSua, tenSua))
                                        Console.Write("\nDa sua thanh cong!");
                                    else
                                        Console.Write("\nKhong the sua!");

                                    Console.Write("\n****************************************\n");
                                    break;
                                case 4:
                                    Console.Write("\n****************************************");
                                    Console.Write("\nNhap ma nhom can xoa: ");
                                    string maXoa = Console.ReadLine();
                                    if (dsNhomThuoc.XoaNT(maXoa))
                                        Console.Write("\nDa xoa thanh cong!");
                                    else
                                        Console.Write("\nKhong the xoa!");

                                    Console.Write("\n****************************************\n");
                                    break;
                                case 5:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Danh sach nhom thuoc<<<<<<\n");
                                    dsNhomThuoc.XuatToanDS();
                                    Console.Write("\n****************************************\n");
                                    break;
                                case 6:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsNhomThuoc.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;
                            }
                        }
                        break;
                    case 2:
                        int chonChucNangThuoc = -1;
                        while (chonChucNangThuoc != 0)
                        {
                            Console.Write("\n________QUAN LY THUOC_______");
                            Console.Write("\n------------------------------");
                            Console.Write("\n\tChon chuc nang:");
                            Console.Write("\n\t1. Nhap thuoc");
                            Console.Write("\n\t2. Tim thuoc");
                            Console.Write("\n\t3. Sua thuoc");
                            Console.Write("\n\t4. Xoa thuoc");
                            Console.Write("\n\t5. Xuat toan bo danh sach thuoc");
                            //Console.Write("\n\t6. Doc danh sach thuoc tu tep");
                            Console.Write("\n\t0. Tro lai danh muc");
                            Console.Write("\n----------------------------\n");
                            while (int.TryParse(Console.ReadLine(), out chonChucNangThuoc) == false)
                            {
                                Console.Write("\nNhap sai, vui long nhap lai!");
                            }
                            switch (chonChucNangThuoc)
                            { 
                                case 1:
                                    Console.Write("\n*********************************\n");
                                    dsThuoc.ThemDSThuoc();
                                    Console.Write("\nDa nhap xong");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 2:
                                    Console.Write("\n*********************************\n");
                                    dsThuoc.TimKiem();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 3:
                                    Console.Write("\nNhap ma thuoc can sua: ");
                                    string macansua = Console.ReadLine();
                                    if (dsThuoc.SuaDSThuoc(macansua))
                                    {
                                        Console.WriteLine("Da sua!");
                                    }
                                    else
                                        Console.WriteLine("Khong the sua. Hay kiem tra lai!");
                                    break;
                                case 4:
                                    Console.Write("\n*********************************\n");
                                    Console.WriteLine("\nNhap ma thuoc can xoa: ");
                                    string macanxoa = Console.ReadLine();
                                    if (dsThuoc.XoaDSThuoc(macanxoa))
                                    {
                                        Console.WriteLine("Da xoa!");
                                    }
                                    else
                                        Console.WriteLine("Khong the xoa!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 5:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\n>>>>>>>>>>>>>>Danh sach thuoc<<<<<<<<<<<<<<\n");
                                    dsThuoc.XuatDSThuoc();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 6:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsThuoc.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;

                            }
                        }
                        break;
                    case 3:
                        
                        int chon = -1;
                        while (chon != 0)
                        {
                            Console.WriteLine("______________QUAN LY NHAN VIEN_____________");
                            Console.WriteLine("Chon chuc nanng: \n\t1: Them vao danh sach \n\t2: Tim kiem \n\t3: Sua \n\t4: Xoa \n\t5: Xuat toan danh sach \n\t0: Quay lai danh muc");
                            while (int.TryParse(Console.ReadLine(), out chon) == false)
                            {
                                Console.WriteLine("Chuc nang khong ton tai!");
                            }
                            switch (chon)
                            {
                                case 1:
                                    Console.Write("\n*********************************\n");
                                    dsNV.ThemNV();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 2:
                                    Console.Write("\n*********************************\n");
                                    dsNV.TimKiem();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 3:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("Nhap ma nhan vien can sua: ");
                                    string suaMa = Console.ReadLine();
                                    if (dsNV.SuaDSNV(suaMa))
                                        Console.WriteLine("Da sua!");
                                    else
                                        Console.WriteLine("Khong the sua. Hay kiem tra lai!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 4:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("Nhap ma nhan vien can xoa: ");
                                    string xoaMa = Console.ReadLine();
                                    if (dsNV.XoaNV(xoaMa))
                                        Console.WriteLine("Da xoa!");
                                    else
                                        Console.WriteLine("Khong the xoa. Hay kiem tra lai!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 5:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\n>>>>>>Danh sach nhan vien<<<<<<\n");
                                    Console.WriteLine("  Ma \t Ho ten \t Ngay sinh \t Dia chi \t Dien thoai \t Luong");
                                    dsNV.XuatNV();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 6:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsNV.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;
                            }
                        }
                        break;
                    case 4:
                        
                        int chucnang = -1;
                        while (chucnang != 0)
                        {
                            Console.WriteLine("____________QUAN LY KHACH HANG____________");
                            Console.WriteLine("Chon chuc nang: \n\t1: Them vao danh sach \n\t2: Tim \n\t3: Sua \n\t4: Xoa \n\t5: Xuat toan danh sach \n\t0: Quay lai danh muc");
                            while (int.TryParse(Console.ReadLine(), out chucnang) == false)
                            {
                                Console.WriteLine("Chuc nang khong ton tai. Hay nhap lai!");
                            }
                            switch (chucnang)
                            {
                                case 1:
                                    Console.Write("\n*********************************\n");
                                    dsKH.ThemDSKH();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 2:
                                    Console.Write("\n*********************************\n");
                                    dsKH.TimKiem();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 3:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\nNhap ma can sua: ");
                                    string SuaMa = Console.ReadLine();
                                    if (dsKH.SuaDSKH(SuaMa))
                                        Console.WriteLine("Da sua!");
                                    else
                                        Console.WriteLine("Khong the sua! Vui long kiem tra lai!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 4:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\nNhap ma can xoa; ");
                                    string XoaMa = Console.ReadLine();
                                    if (dsKH.XoaKH(XoaMa))
                                        Console.WriteLine("Da xoa!");
                                    else
                                        Console.WriteLine("Khong the xoa!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 5:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\n>>>>>>Danh sach khach hang<<<<<<\n");
                                    Console.WriteLine("-------------------------------------------");
                                    Console.WriteLine("\tMa \tHo ten \t Dia chi \tDien thoai");
                                    dsKH.XuatDSKH();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 6:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsKH.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;
                            }

                        }
                        break;
                    case 5:
                        int chonCN_HD = -1;
                        while (chonCN_HD != 0)
                        {
                            Console.Write("\n_____QUAN LY HOA DON____");
                            Console.Write("\n----------------------------");
                            Console.Write("\nChon chuc nang:");
                            Console.Write("\n\t1. Them hoa don");
                            Console.Write("\n\t2. Tim hoa don");
                            Console.Write("\n\t3. Sua hoa don");
                            Console.Write("\n\t4. Xoa hoa don");
                            Console.Write("\n\t5. Xuat toan bo hoa don");
                            //Console.Write("\n\t6. Doc danh sach hoa don tu tep");
                            Console.Write("\n\t0. Tro lai danh muc");
                            Console.Write("\n----------------------------\n");
                            while (int.TryParse(Console.ReadLine(), out chonCN_HD) == false)
                            {
                                Console.Write("\nNhap sai, vui long nhap lai!");
                            }
                            switch (chonCN_HD)
                            {
                                case 1:
                                    Console.Write("\n*********************************\n");
                                    dsHD.ThemDSHD();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 2:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\nNhap ma can tim: ");
                                    string timMa = Console.ReadLine();
                                    HoaDon HDTim = dsHD.TimHD(timMa);
                                    if (HDTim != null)
                                        HDTim.XuatHD();
                                    ///dsHD.TimHD();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 3:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\nNhap ma can sua: ");
                                    string maSua = Console.ReadLine();
                                    dsHD.suaHoaDon(maSua);
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 4:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\nNhap ma can xoa; ");
                                    string XoaMa = Console.ReadLine();
                                    if (dsKH.XoaKH(XoaMa))
                                        Console.WriteLine("Da xoa!");
                                    else
                                        Console.WriteLine("Khong the xoa!");
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 5:
                                    Console.Write("\n*********************************\n");
                                    Console.Write("\n>>>>>>Danh sach hoa don<<<<<<\n");
                                    Console.WriteLine("-------------------------------------------");
                                    Console.WriteLine("\tMa \tTen nhan vien \tTen khach hang \tNgay lap \tThanh tien");
                                    dsHD.XuatDSHD();
                                    Console.Write("\n*********************************\n");
                                    break;
                                case 6:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsHD.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;
                            }
                        }
                        break;
                    case 6:
                        int chonCN_CTHD = -1;
                        while (chonCN_CTHD != 0)
                        {
                            Console.Write("\n_____CHI TIET HOA DON____");
                            Console.Write("\n----------------------------");
                            Console.Write("\nChon chuc nang:");
                            Console.Write("\n\t1. Nhap chi tiet HD");
                            Console.Write("\n\t2. Xem chi tiet HD");                            
                            Console.Write("\n\t0. Tro lai danh muc");
                            Console.Write("\n----------------------------\n");
                            while (int.TryParse(Console.ReadLine(), out chonCN_CTHD) == false)
                            {
                                Console.Write("\nNhap sai, vui long nhap lai!");
                            }
                            switch (chonCN_CTHD)
                            { 
                                case 1:
                                    Console.Write("\n------------------------------------\n");
                                    dsCTHD.ThemDS();
                                    Console.Write("\n------------------------------------\n");
                                    break;
                                case 2:

                                    Console.WriteLine(">>>>>>>>>Chi tiet hoa don<<<<<<<<");
                                    Console.Write("\n------------------------------------\n");
                                    dsCTHD.XuatDsCTHD();
                                    break;
                                case 3:
                                    Console.Write("\n****************************************");
                                    Console.Write("\n>>>>>>Doc file<<<<<<\n");
                                    dsCTHD.docFile();
                                    Console.Write("\n****************************************\n");
                                    break;
                            }
                        }
                        break;
                }
            }
        }
        
    }
}
